package com.ete.service.widget

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.util.AttributeSet
import androidx.annotation.ColorRes
import androidx.constraintlayout.widget.ConstraintLayout
import com.blankj.utilcode.util.ColorUtils
import com.ete.service.service.R


/**
 * Author:LiXian
 * <p>
 * Desc:TODO
 * Version:1.0
 * date 2023/12/20 9:18
 */
class CustomConstraintLayout : ConstraintLayout {

    constructor(
            mContext: Context, mAttrs: AttributeSet? = null,
            mDefStyleAttr: Int = 0, mDefStyleRes: Int = 0
    ) : super(mContext, mAttrs, mDefStyleAttr, mDefStyleRes) {
        updateGradientBg(R.color.color_3F73ED)
    }

    constructor(mContext: Context, mAttrs: AttributeSet? = null)
            : this(mContext, mAttrs, 0, 0)

    constructor(mContext: Context) : this(mContext, null)

    fun updateGradientBg(@ColorRes startColor: Int) {
        if (startColor == 0) return
        val colors = IntArray(2)
        colors[0] = ColorUtils.getColor(startColor)
        colors[1] = Color.WHITE
        val gradientDrawable = GradientDrawable(
                GradientDrawable.Orientation.TOP_BOTTOM,
                colors
        )
        background = gradientDrawable
    }

}